require('dotenv').config();
// 创建HTTP服务
const express = require("express")
const bodyParser = require('body-parser');
const path = require("path")
const cors = require("cors")
const app = express()

const port = process.env.PORT


// POST
// 解析 application/x-www-form-urlencoded  文档格式
app.use(bodyParser.urlencoded())
// 解析 application/json 文档格式
app.use(bodyParser.json())

// 设置资源跨域共享
app.use(cors())

// 设置静态资源目录
// __dirname
app.use("/static", express.static(path.resolve(__dirname, "public")))
app.use("/admin", express.static(path.resolve(__dirname, "admin")))
// http://120.26.30.18:3001/cms/
app.use("/cms", express.static(path.resolve(__dirname, "cms")))
// http://120.26.30.18:3001/app/
app.use("/app", express.static(path.resolve(__dirname, "app")))

// 设置URL并导入路由文件
app.use('/api/banner', require("./router/banner.js"))
app.use('/api/cate', require("./router/cate.js"))
app.use('/api/user', require("./router/user.js"))
app.use('/api/article', require("./router/article.js"))
app.use('/api/admin', require("./router/admin.js"))
app.use('/api/photo', require("./router/photo.js"))
app.use('/api/note', require("./router/note.js"))
app.use('/api/noteComment', require("./router/noteComment.js"))
app.use('/api/wish', require("./router/wish.js"))
app.use('/api/msg', require("./router/message.js"))
app.use('/api/out', require("./router/out.js"))
app.use('/api/picture', require("./router/picture.js"))
app.use('/api/articleComment', require("./router/articleComment.js"))

app.listen(port, () => {
    console.log("http 启动成功 ~~", port)
})

